﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VCDIFF.Visit;
using VCDIFF.Rebuild;

namespace VCDIFF
{
    public class VCDFile
    {
        public Header Header { get; set; }
        public IList<Window> WindowsList { get; set; }

        /// <summary>
        /// VCDFile's constructor
        /// </summary>
        public VCDFile()
        {
            WindowsList = new List<Window>();
        }

        /// <summary>
        /// Reads VCDIFF File.
        /// </summary>
        /// <param name="path">Path where is read VCDIFF File.</param>
        public void Read(string path)
        {
            Reader reader = new Reader(path);
            reader.Visit(this);
        }

        /// <summary>
        /// Writes VCDIFF File.
        /// </summary>
        /// <param name="path">Path where is written VCDIFF File.</param>
        public void Write(string path)
        {
            Writer writer = new Writer();
            writer.Visit(this);
            writer.Write(path);
        }

        public static void Serialize(VCDFile vcdFile, string filePath)
        {
            RebuildFile target = new RebuildFile();
            target.Rebuild(vcdFile.WindowsList, filePath);
            target.Write(filePath + "_modified");
        }
    }
}
